package net.adetech.crj.service;

import net.adetech.crj.dao.AppointmentMapper;
import net.adetech.crj.entity.Appointment;
import net.adetech.crj.utils.InnerServiceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service("appointment.getCurrentListByIdNumber")
public class GetCurrentAppointmentListByIdNumberService implements BaseService {

    @Autowired
    AppointmentMapper appointmentMapper;

    @Override
    public Map<String, Object> invoke(Map<String, Object> params) {
        Date now = new Date();
        String idNumber = (String) params.get("idNumber");
        String serviceType = (String) params.get("serviceType");
        String dayId = new SimpleDateFormat("yyyyMMdd").format(now);
        int time = Integer.parseInt(new SimpleDateFormat("HHmm").format(now));
        int timePeriod = 1;
        if (time >= 830 && time <= 1000) {
            timePeriod = 0;
        } else if (time > 1000 && time <= 1130) {
            timePeriod = 1;
        } else if (time >= 1330 && time <= 1500) {
            timePeriod = 2;
        } else if (time > 1500 && time <= 1630) {
            timePeriod = 3;
        }
        if ("CHINESE".equals(serviceType)) {
            serviceType = "A";
        } else if ("FOREIGNER".equals(serviceType)) {
            serviceType = "B";
        }
        else if ("MANAGER".equals(serviceType)) {
            serviceType = "M";
        }



//        else {
//            return InnerServiceUtil.buildResult("appointmentList",new ArrayList<Appointment>());
//        }

        List<Appointment> appointmentList = appointmentMapper.getCurrentAppointmentListByIdNumber(idNumber, dayId, timePeriod,serviceType);
        return InnerServiceUtil.buildResult("appointmentList", appointmentList);
    }
}
